package com.example.music_project.pages;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;

import com.example.music_project.R;

/*音乐播放器启动类1.0*/

public class MusicPlayMainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.fragment_music_data);



        Intent intent = getIntent();
        TextView nameText = findViewById(R.id.text_name);
        ImageView musicImg = findViewById(R.id.img_imgId);
        TextView lyric = findViewById(R.id.text_lyric);

        nameText.setText(intent.getStringExtra("musicName"));
        musicImg.setImageResource(intent.getIntExtra("musicImg", R.drawable.sea));
        lyric.setText(intent.getStringExtra("musicLyric"));

        // 返回
        ImageView btnBack = findViewById(R.id.btn_back);
        btnBack.setOnClickListener(v -> finish());

        // 评论按钮 - 跳转到评论页面
        ImageView btnComment = findViewById(R.id.btn_comment);
        btnComment.setOnClickListener(v -> {
            Intent commentIntent = new Intent(MusicPlayMainActivity.this, CommentActivity.class);
            // 传递音乐相关信息
            commentIntent.putExtra("music_id", intent.getStringExtra("musicId")); // 假设有musicId
            commentIntent.putExtra("music_name", intent.getStringExtra("musicName"));
            startActivity(commentIntent);
        });

    }

    /* 播放 */
    public void playBack(View view) {
        Intent intent = new Intent();
        TextView nameText = findViewById(R.id.text_name);
        intent.putExtra("favouriteName",nameText.getText().toString());
        setResult(RESULT_OK,intent);
        finish();
    }


}